package cn.stylefeng.guns.modular.hx.order.controller;

import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.basic.service.BasicCustomerService;
import cn.stylefeng.guns.modular.basic.service.BasicWarehouseService;
import cn.stylefeng.guns.modular.hx.order.model.params.HxOrderOutParam;
import cn.stylefeng.guns.modular.hx.order.service.HxOrderOutService;
import cn.stylefeng.guns.modular.transport.utils.MapTrackUtils;
import cn.stylefeng.guns.sys.modular.system.entity.User;
import cn.stylefeng.guns.sys.modular.system.service.UserService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author : like
 * @date : 2024/8/9 18:05
 * @Version: 1.0
 */
@Api(tags = "出库订单预排车")
@Controller
@RequestMapping("/hxOrderOutMap")
public class HxOrderOutMapController {

    private String PREFIX = "/hx/order/hxOrderOutMap";

    @Autowired
    private UserService userService;

    @Autowired
    private BasicWarehouseService basicWarehouseService;

    @Autowired
    private BasicCustomerService basicCustomerService;

    @Autowired
    private HxOrderOutService hxOrderOutService;

    @Autowired
    private MapTrackUtils mapTrackUtils;


    @RequestMapping("")
    public String index(Model model) {
        User user = userService.getcurrentUser();
        Long deptId = user.getDeptId();
        Long deliverId = user.getDeliverId();
        //查询可选择仓库
        model.addAttribute("basicWarehouseList", basicWarehouseService.findAvailableList(deptId,deliverId,user.getOperateId()));
        //查询可选择客户
        model.addAttribute("customerlist", basicCustomerService.findAvailableList(deptId,deliverId,user.getOperateId()));
        return PREFIX + "/hxOrderOutMap.html";
    }

    // 查询排车门店
    @ResponseBody
    @RequestMapping("/listNew")
    public LayuiPageInfo listNew(HxOrderOutParam param,String condition) {
        User user = userService.getcurrentUser();
        param.setDeptId(user.getDeptId());
        param.setDeliverId(user.getDeliverId());
        // 判断时间为空则设置当前日期
        if (param.getPeisongTime() == null || param.getPeisongTime().isEmpty()) {
            SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
            // 获取当前日期并格式化
            String currentDate = dateFormat.format(new Date());
            // 设置参数的 peisongTime 属性
            param.setPeisongTime(currentDate);
        }
        return hxOrderOutService.findPageByMap(param, condition,user.getOperateId());
    }


}
